package lifei.lifei.mybatis.jdbcdemo;


import java.sql.*;
import java.util.Date;

public class LinkTabInsert {
    public static void main(String[] args)
            throws ClassNotFoundException, SQLException {
        //注册驱动
        Class.forName("com.mysql.cj.jdbc.Driver");
        //获取连接
        Connection conn = DriverManager.getConnection(
                "jdbc:mysql:///jtsys?serverTimezone=GMT",
                "root",
                "root");
        System.out.println(conn);
        //定义SQL
        String sql = "insert into sys_logs " +
                "(username,time,createdTime) " +
                "values(?,?,?)";
        //创建传输器对象
        PreparedStatement ps = conn.prepareStatement(sql);
            //设置占位符的值
            ps.setObject(1, "lifei");
            ps.setObject(2, 12315);
            ps.setObject(3, new Date(System.currentTimeMillis()));
        //执行SQL
        long rows = ps.executeLargeUpdate();
        //处理结果集
        if (rows>0){
            System.out.println("新增成功");
        }else {
            System.out.println("新增失败");
        }
        //释放资源
        ps.close();
        conn.close();

    }



}
